package client;
import java.awt.*;
import java.awt.event.*;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import server.*;
import java.awt.Dialog;

/**
 * 
 * @author Jesse Gorter
 *
 */
public class MyLoginCard extends Panel implements ActionListener, ComponentListener
{	
	TextField usertext, passtext;
	Label userlabel, passlabel, errorlabel;
	GridBagLayout gbl = new GridBagLayout();
	private static String service = "rmi://localhost/"+Login.refName;
	private MyApplet ap;
	
	public MyLoginCard(MyApplet applet)
	{	
		ap = applet;
		usertext = new TextField(10);
		passtext = new TextField(10);
		userlabel = new Label("user");
		passlabel = new Label("password");
		errorlabel = new Label();
		this.setBackground(new Color(204, 255, 255));
		
		Insets insets = new Insets(0, 10, 10,0);
		this.setLayout(gbl);
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.insets = insets;
		gbc.gridx = 0; gbc.gridy= 0;
		
		this.add(userlabel, gbc);
		gbc.gridx =1;
		this.add(usertext, gbc);
		gbc.gridy=1;
		gbc.gridx = 0;
		this.add(passlabel, gbc);
		gbc.gridx=1;
		this.add(passtext, gbc);
	
	}
	
	public void text()
	{
		
	}
	public void login()
	{
		try {
			Login login = (Login)Naming.lookup(service);
			Cijferlijst rem = (Cijferlijst)login.login(usertext.getText(), passtext.getText());
			if(rem == null)
			{	
				ap.setText("login gefaald");
			}
			else
			{	
				ap.setText("Cijfer tabel");
				
				
				this.repaint();
				this.validate();
				System.out.println(rem);
				ap.loadCijferlijst(rem);
				System.out.println("nu de cijferlijstcard showen!");
			}
			
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch(NullPointerException e)
		{
			System.out.println("foute wachtwoord/username combinatie");
		} catch(ClassCastException e)
		{
			System.out.println("foute wachtwoord/username combinatie");
			System.out.println("classcastexception");
		}
		
	}
	public void actionPerformed(ActionEvent e)
	{
		
	}
	
	public void componentHidden(ComponentEvent arg0) {
				
	}
	public void componentMoved(ComponentEvent arg0) {
				
	}
	public void componentResized(ComponentEvent arg0) {
				
	}
	public void componentShown(ComponentEvent arg0) {
				
	}
}
